#include <iostream>
#include <queue>
#include <stdlib.h>  
#include <algorithm>
#include <cmath>
#include <fstream>
#include <string>
#include "../Simulator/Application.h"
void generateApplications(int numApplication, int numTasksRange, double CCR, int arrivalRate, int taskVol, string filenamePrefix) {
	//queue<Event> events;
	int range = 1000;//arrival time range;
	int appCount = 0;
	double countSum = 0.0;
	for (int i = 0; appCount < numApplication && i < range; i++) {
		countSum += arrivalRate;
		int count = countSum;
		countSum -= count;
		//int count = arrivalRate*(cos(3.14 + i) + 1) + 1;//0~3 arrival rate
		for (int j = 0; appCount < numApplication && j < count; j++) {
			int nt = rand() % numTasksRange + 1;
			Application app(nt, CCR + (nt % 4) / 100 - 0.002, i, appCount, taskVol);//task number
			app.saveAsFile(filenamePrefix);
			appCount++;
		}
	}
	//return events;
}

int main(int argc, char* argv[]) {
	
	int numApplication = atoi(argv[1]);// 16 32 64 128 //64
	int numTasksRange = atoi(argv[2]);//8 16 24 32 //24
	int taskExecutionVolume = atoi(argv[3]);//8 16 24 32 64 // 16
	double CCR = atof(argv[4]); //threshold 0.1
	double arrivalRate = atof(argv[5]);//0 2 4 6 // 4
	
	string applicationString = "app\\app";
	generateApplications(numApplication, numTasksRange, CCR, arrivalRate, taskExecutionVolume, applicationString);
	//generateApplications(10, 10, 0.005, 5, 128, applicationString);
	return 0;
}